package course.service.impl;

import course.dao.StuTeaDao;
import course.dao.impl.StuTeaDaoImpl;
import course.pojo.entity.StuTea;
import course.service.StuTeaService;
import course.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @author HLF
 * @date 2022/7/3 18:57
 */
public class StuTeaServiceImpl implements StuTeaService {
    private StuTeaDao stuTeaDao = new StuTeaDaoImpl();

    @Override
    public int addStuTea(StuTea stuTea) {
        Connection connection = JDBCUtil.getConnection();
        int i = stuTeaDao.addStuTea(stuTea, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public List<StuTea> getList() {
        Connection connection = JDBCUtil.getConnection();
        List<StuTea> list = stuTeaDao.getList(connection);
        JDBCUtil.closeConnection(connection);
        return list;
    }

    @Override
    public List<StuTea> getBySid(Integer sid) {
        Connection connection = JDBCUtil.getConnection();
        List<StuTea> bySid = stuTeaDao.getBySid(sid, connection);
        JDBCUtil.closeConnection(connection);
        return bySid;
    }

    @Override
    public List<StuTea> getByTid(Integer tid) {
        Connection connection = JDBCUtil.getConnection();
        List<StuTea> byTid = stuTeaDao.getByTid(tid, connection);
        JDBCUtil.closeConnection(connection);
        return byTid;
    }

    @Override
    public List<StuTea> getBySuid(Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        List<StuTea> bySuid = stuTeaDao.getBySuid(suid, connection);
        JDBCUtil.closeConnection(connection);
        return bySuid;
    }

    @Override
    public List<StuTea> getBySidSuid(Integer sid, Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        List<StuTea> bySuid = stuTeaDao.getBySidSuid(sid, suid, connection);
        JDBCUtil.closeConnection(connection);
        return bySuid;
    }

    @Override
    public List<StuTea> getByTidSuid(Integer tid, Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        List<StuTea> bySuid = stuTeaDao.getByTidSuid(tid, suid, connection);
        JDBCUtil.closeConnection(connection);
        return bySuid;
    }

    @Override
    public List<StuTea> getBySidTidSuid(Integer sid, Integer tid, Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        List<StuTea> bySidTidSuid = stuTeaDao.getBySidTidSuid(sid, tid, suid, connection);
        JDBCUtil.closeConnection(connection);
        return bySidTidSuid;
    }

    @Override
    public int deleteBySidTidSuid(Integer sid, Integer tid, Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        int i = stuTeaDao.deleteBySidTidSuid(sid, tid, suid, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public int deleteByTidSuid(Integer tid, Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        int i = stuTeaDao.deleteByTidSuid(tid, suid, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public List<Integer> getSuids(Integer tid) throws SQLException {
        Connection connection = JDBCUtil.getConnection();
        List<Integer> suids = stuTeaDao.getSuids(tid,connection);
        JDBCUtil.closeConnection(connection);
        return suids;
    }
}
